package com.student.wym.mapper;

import com.student.wym.po.Exam;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface ExamMapper {

    @Select("select e.* from ks_exam e where e.state = 0 or e.state = 1")
    Exam findCurrentExam();

    @Select("select count(*) from ks_exam")
    Integer findTotal();

    @Select("select * from ks_exam order by create_time desc")
    List<Exam> findAll();

    @Delete("delete from ks_exam where id = #{id}")
    void delete(int id);

    @Insert("insert into ks_exam(exam_name,exam_time,create_time,state,radio_num,radio_score,check_num,check_score,judge_num,judge_score,pass,againe)"
            + " values(#{examName},#{examTime},#{createTime},#{state},#{radioNum},#{radioScore},#{checkNum},#{checkScore},#{judgeNum},#{judgeScore},#{pass},#{againe})")
    void saveOne(Exam exam);

    @Select("select count(*) from ks_exam where state != 2")
    Integer findNot();

    @Update("update ks_exam set state = 2 where state = 1")
    void endCurrentExam();

    @Update("update ks_exam set state = 1 where state = 0")
    void startCurrentExam();

    @Select("select e.* from ks_exam e where e.state = 0")
    Exam findCurrentExam2();

}
